package com.quectel.sdk.quecentrance;

import com.quectel.sdk.ex.hikisc.HikFactoryErrorException;

/**
 * 移远门禁实例建造器
 *
 * @author: rananxin
 * @email: ryan.ran@quectel.com
 * @date: 2022-10-19 11:01:00
 */
public class QuecEntranceClientBuilder {

    /**
     * appKey访问凭证
     */
    private String appKey;
    /**
     * secretKey访问凭证
     */
    private String appSecret;

    /**
     * 移远门禁平台地址
     */
    private String baseUrl;

    private QuecEntranceClientBuilder() {
    }

    public static QuecEntranceClientBuilder builder() {
        return new QuecEntranceClientBuilder();
    }

    public QuecEntranceClientBuilder appKey(String appKey) {
        this.appKey = appKey;
        return this;
    }

    public QuecEntranceClientBuilder appSecret(String appSecret) {
        this.appSecret = appSecret;
        return this;
    }


    public QuecEntranceClientBuilder baseUrl(String baseUrl) {
        this.baseUrl = baseUrl;
        return this;
    }

    public <T extends AbstractQuecEntranceBaseClient> T build(Class<T> executorCls) {
        if (baseUrl == null || appKey == null || appSecret == null) {
            throw new HikFactoryErrorException("Missing request parameter.");
        }
        try {
            T t = executorCls.newInstance();
            t.setRequester(QuecEntranceRequester.getInstance(baseUrl, appKey, appSecret));
            return t;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
